package cc.sheji;

import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;


public class Test {


    public static String merchantId = "1612407211";

    /**
     * 商户API私钥路径
     */
    public static String privateKeyPath = "C:\\Users\\tom\\apiclient_key.pem";
    /**
     * 商户证书序列号
     */
    public static String merchantSerialNumber = "598F16A99583B2A92C1C48F5FC15C5C36615C786";
    /**
     * 商户APIV3密钥
     */
    public static String apiV3key = "al35wx22kf28ny1908830912et13301x";

    public static void main(String[] args) {


        RSAAutoCertificateConfig config = new RSAAutoCertificateConfig.Builder()
                .merchantId(merchantId)
                .privateKeyFromPath(privateKeyPath)
                .merchantSerialNumber(merchantSerialNumber)
                .apiV3Key(apiV3key)
                .build();




        JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build();

// 跟之前下单示例一样，填充预下单参数
        PrepayRequest request= new PrepayRequest();


        Amount amount = new Amount();
        amount.setTotal(100);
        request.setAmount(amount);
        request.setAppid("wx85dd784a1d6ddc9d");
        request.setMchid("1612407211");
        request.setDescription("测试商品标题");
        request.setNotifyUrl("https://notify_url");
        request.setOutTradeNo("out_trade_no_0011");
        Payer payer = new Payer();
        payer.setOpenid("oEI9B45WGpmc_2mcHNpPTFuUnAYY");
        request.setPayer(payer);


// response包含了调起支付所需的所有参数，可直接用于前端调起支付
        PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request);



        System.out.println(response.toString());
    }
}
